<template>
<div>login view</div>
<el-button plain @click="setToken">set token</el-button>
<el-button plain @click="loginBtn">login</el-button>
</template>

<script setup lang="ts">

import { PROJECT_KEY } from '@/config';
import { useTokenStore, usePermissionStore } from '@glz/utils';
import type { ApiRequest, LoginInfoReq } from "@glz/apis";
import { login , navbar } from "@glz/apis";
import { useRouter } from 'vue-router';


const tokenInfo = useTokenStore(PROJECT_KEY)
const router = useRouter()
const permissionInfo = usePermissionStore()

const setToken = () => {
    tokenInfo.setToken("123456798")
    router.push("/home")
}

const loginBtn = async ()=>{

   const loginInfo :LoginInfoReq = {
        username:'0112',
        password:'******',
        userrole:''
   }

   const req : ApiRequest<LoginInfoReq> = {
            device:1,
            lang:"zh-tw",
            oData:loginInfo
           }

   const resp = await login.login(req);

   tokenInfo.setToken(resp.data.token)

 
   // navbar.route
   navbar.setToken(resp.data.token);

   const navresp = await navbar.route();

   permissionInfo.setPermission(navresp.data.navbarUsersList)

   console.log("navresp",navresp.data)

   router.push('/home')

   console.log("resp",resp)
}

</script>